package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /**
     *====================== 原始分页查询================================================
     */
    //查询总记录数
//    @Select("select count(*) from emp  e left outer join  dept d on e.dept_id = d.id ;")
//    public Long count();
//    //查询分页数据
//    public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end, Integer start, Integer pageSize);

    /**
     * ====================== 插件分页查询================================================
     */
//    @Select("select e.*,d.name deptName from emp  e left outer join  dept d on e.dept_id = d.id order by e.update_time desc ")
//        public List<Emp> list();

//    List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    /**
     * 1 条件分页查询
     * @param empQueryParam
     * @return
     */
    List<Emp> list(EmpQueryParam empQueryParam);





    /**
     * 2 新增员工基本信息
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")//主键返回
    @Insert("insert into emp (username,name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "VALUES(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 3 查询所有员工信息
     * @return
     */
    @Select("select  id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time from emp;")
    List<Emp> findAll();

    /**
     * 4 批量删除员工
     * @param ids
     */

    void deleteByIds(List<Integer> ids);

    /**
     * 5 根据id查询员工信息和员工经历信息
     * @param id
     * @return
     */
    Emp getById(Integer id);

    /**
     * 6 根据修改员工信息
     * @param emp
     */
    void updateById(Emp emp);

    /**
     * 7 统计员工职位人数
     */
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();


    /**
     * 8 统计员工性别人数
     */
    @MapKey("name")
    List<Map<String,Object>> countEmpGenderData();

    /**
     * 登录
     * @param emp
     * @return
     */
    @Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}